package com.example.administrator.myapplication.view;

import android.content.Context;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.utils.PublicTools;


/**
 * Toast自定义统一管理类
 *
 * @author LiJL
 *
 */
public class ToastView {
	/**
	 *
	 * Toast自定义方法,背景色为:0x8064615f;
	 *
	 * @param context
	 *            :getApplicaitonContext();
	 * @param str
	 *            :需要打印的字符
	 * @param duration
	 *            :显示的时间长短，如：Toast.LENGTH_SHORT，Toast.LENGTH_LONG
	 */
	public static void ToastShow(Context context, int strId, int duration) {
		ToastShow(context,context.getString(strId),duration);
	}
	public static void ToastShow(Context context, String str, int duration) {
		Toast toast = Toast.makeText(context, str, duration);
		toast.setGravity(Gravity.BOTTOM,Gravity.CENTER_HORIZONTAL, PublicTools.dip2px(100));// Gravity.TOP表示在顶部，Gravity.CENTER:表示在中间；Gravity.BOTTOM:表示在底部

		LinearLayout linear = new LinearLayout(context);
		linear.setBackgroundResource(R.drawable.toast_bg);
		linear.setOrientation(LinearLayout.VERTICAL);
		linear.setPadding(30, 20, 30, 20);
		// LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
		// LinearLayout.LayoutParams.WRAP_CONTENT,
		// LinearLayout.LayoutParams.WRAP_CONTENT, 1); // , 1是可选写的
		// lp.setMargins(10, 20, 30, 40);
		// linear.setLayoutParams(lp);
		TextView txtView = new TextView(context);
		txtView.setTextColor(0xffffffff);
		txtView.setTextSize(15);
		txtView.setText(str);

		int lHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
		int lWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
		linear.addView(txtView, new LinearLayout.LayoutParams(lWidth, lHeight));

		linear.setPadding(20, 10, 20, 10);

		toast.setView(linear);
		toast.show();
	}
}
